//
//  NSTimer+Extension.m
//  CommoniOSDemo
//
//  Created by arronzhu on 2017/8/1.
//  Copyright © 2017年 arronzhu. All rights reserved.
//

#import "NSTimer+Extension.h"

@implementation NSTimer (Extension)

+ (NSTimer *)hr_scheduledTimerWithTimeInterval:(NSTimeInterval)inTimeInterval block:(void (^)(void))block repeats:(BOOL)repeats
{
    void (^cblock)(void) = [block copy];
    NSTimer * timer = [self scheduledTimerWithTimeInterval:inTimeInterval target:self selector:@selector(__executeTimerBlock:) userInfo:cblock repeats:repeats];
    return timer;
}

+ (NSTimer *)hr_timerWithTimeInterval:(NSTimeInterval)inTimeInterval block:(void (^)(void))block repeats:(BOOL)repeats
{
    void (^cblock)(void) = [block copy];
    NSTimer * timer = [self timerWithTimeInterval:inTimeInterval target:self selector:@selector(__executeTimerBlock:) userInfo:cblock repeats:repeats];
    return timer;
}

+ (void)__executeTimerBlock:(NSTimer *)timer;
{
    if([timer userInfo])
    {
        void (^block)(void) = (void (^)(void))[timer userInfo];
        block();
    }
}

@end
